/*
 * @Descripttion: 
 * @version: 
 * @Author: TT
 * @Date: 2021-10-03 10:22:52
 * @LastEditors: TT-hzy
 * @LastEditTime: 2024-10-17 09:47:15
 */

import 'package:flutter/material.dart';

import '../comment_tools/comment_tools.dart';

enum BtnlayoutType { leftimage, topimage, rightimage, bottomimage, text, image }

class BtnItemWidget extends StatelessWidget {
  final GestureTapCallback? ontap;
  final Widget? title;
  final Widget? image;
  final BtnlayoutType layoutType;
  final Size? widgetSize;
  final BoxDecoration? decoration;
  final double? space;
  final EdgeInsetsGeometry? padding;
  const BtnItemWidget(
    this.layoutType, {
    Key? key,
    this.widgetSize,
    this.title,
    this.image,
    this.decoration,
    this.space,
    this.ontap,
    this.padding,
  }) : super(key: key);
  @override
  Widget build(BuildContext context) {
    return InkWell(
      onTap: () {
        if (ontap != null) {
          ontap!();
        }
      },
      child: Container(
        padding: padding,
        decoration: decoration,
        alignment: Alignment.center,
        width: widgetSize?.width,
        height: widgetSize?.height,
        child: (layoutType == BtnlayoutType.image ||
                layoutType == BtnlayoutType.text)
            ? createNoramlWidget()
            : createColumWidget(),
      ),
    );
  }

  Widget createNoramlWidget() {
    if (layoutType == BtnlayoutType.image) {
      return image ?? Container();
    } else if (layoutType == BtnlayoutType.text) {
      return title ?? Container();
    } else {
      return Container();
    }
  }

  Widget createColumWidget() {
    Widget imageWidget = image ?? Container();
    Center titleWidget = Center(child: title ?? Container());
    double spaced = space ?? 5;
    Widget childe = Container();
    if (layoutType == BtnlayoutType.leftimage) {
      childe = Row(
        mainAxisAlignment: MainAxisAlignment.center,
        crossAxisAlignment: CrossAxisAlignment.center,
        children: [imageWidget, Gaps.confighbox(space ?? 5), titleWidget],
      );
    } else if (layoutType == BtnlayoutType.rightimage) {
      childe = Row(
        mainAxisAlignment: MainAxisAlignment.center,
        crossAxisAlignment: CrossAxisAlignment.center,
        children: [
          titleWidget,
          Gaps.confighbox(spaced),
          imageWidget,
        ],
      );
    } else if (layoutType == BtnlayoutType.topimage) {
      childe = Column(
        mainAxisAlignment: MainAxisAlignment.center,
        crossAxisAlignment: CrossAxisAlignment.center,
        children: [imageWidget, Gaps.configvbox(spaced), titleWidget],
      );
    } else if (layoutType == BtnlayoutType.bottomimage) {
      childe = Column(
        mainAxisAlignment: MainAxisAlignment.center,
        crossAxisAlignment: CrossAxisAlignment.center,
        children: [titleWidget, Gaps.configvbox(spaced), imageWidget],
      );
    }

    return Container(
      child: childe,
    );
  }
}
